package com.bbm.bbmanage.controller;


import com.bbm.bbmanage.entity.Reserve;
import com.bbm.bbmanage.entity.vo.ResponseResult;
import com.bbm.bbmanage.entity.dto.IdList;
import com.bbm.bbmanage.service.ReserveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 房间预定表(Reserve)表控制层
 *
 * @author lionkliu
 * @since 2023-12-13 11:41:42
 */
@RestController
@RequestMapping("reserve")
public class ReserveController {

    @Resource
    private ReserveService reserveService;

    // 查询已支付订单
    @GetMapping("/my/{userId}")
    public ResponseResult getIsPayReserveByUserId(@PathVariable Integer userId) {
        return reserveService.getReserveByUserId(userId);
    }

    @GetMapping("/order/{userId}")
    public ResponseResult getNoPayReserveByUserId(@PathVariable Integer userId) {
        return reserveService.getNoPayReserveByUserId(userId);
    }

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return reserveService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/search")
    public ResponseResult search(@RequestParam(value = "userId", required = false) Integer userId,
                                 @RequestParam(value = "houseId", required = false) Integer houseId,
                                 @RequestParam(value = "isPay", required = false) Integer isPay,
                                 @RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize) {
        return reserveService.search(pageNum, pageSize, isPay, userId, houseId);
    }


    @PostMapping
    public ResponseResult insert(@RequestBody Reserve reserve) {
        return reserveService.insertOne(reserve);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Reserve reserve) {
        return reserveService.updateOne(reserve);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return reserveService.deleteById(id);
    }

    @DeleteMapping("batch")
    public ResponseResult deleteBatchByIds(@RequestBody IdList ids) {
        return reserveService.deleteBatchByIds(ids);
    }

    @PutMapping("batch")
    public ResponseResult updateBatchByIds(@RequestBody IdList reserveList) {
        return reserveService.updateBatchByIds(reserveList);
    }

}
